import snowboydecoder
import signal

def wait_for_wakeup(model_path="resources/models/your_wakeword.pmdl", callback=None):
    """
    等待唤醒词检测，检测到后执行callback。
    :param model_path: 唤醒词模型路径
    :param callback: 检测到唤醒词后执行的回调函数
    """
    def detected_callback():
        print("唤醒词检测到！")
        # 检测到唤醒词后执行回调
        if callback:
            callback()
    try:
        # 创建唤醒词检测器
        detector = snowboydecoder.HotwordDetector(model_path, sensitivity=0.5)
        print("唤醒模块已启动，等待唤醒词...")
        # 阻塞，直到检测到唤醒词
        detector.start(detected_callback=detected_callback, sleep_time=0.03)
        detector.terminate()
    except Exception as e:
        print(f"唤醒模块异常: {e}") 